﻿using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.Templates;
using PasswordSafe.Classes;

namespace PasswordSafe
{
    public class DetailListBox:ListBoxBase
    {
        protected override void InitControl()
        {
            base.InitControl();
            //ShowHeader = false;
            detail = new DetailTemplate();
            ItemTemplate = detail;
            ItemHeight = ItemTemplate.Height;
        }

        private DetailTemplate detail;

        private NotifyList details;

        public NotifyList Details
        {
            get { return details; }
            set
            {
                if (details != value)
                {
                    details = value;
                    //ShowHeader = value != null && value.Count > 3 && value[0] is IGroupHeader;
                    DataSource = value;
                }
            }
        }


        public override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
        {
        switch (e.KeyCode)
            {                
                case System.Windows.Forms.Keys.Enter:
                    detail.Bind(SelectedItemIndex);
                    detail.Focus();
                    e.Handled = true;
                    break;
            }
            base.OnKeyDown(e);
        }

        public override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
                case '\r': break;
                case '\t': SelectNextItem(); break;
                default: detail.InsertKey(e); break;
            }
            base.OnKeyPress(e);
        }


        public DetailTemplate DetailTemplate { get { return ItemTemplate as DetailTemplate; } }


        protected override void OnItemClick(int index)
        {
            base.OnItemClick(index);
            DetailTemplate.Focus();
        }

    }
}
